package cn.wxq.daily.empdailymgforserve.service.impl;

import cn.wxq.daily.empdailymgforserve.domain.Administrative;
import cn.wxq.daily.empdailymgforserve.mapper.AdministrativeDao;
import cn.wxq.daily.empdailymgforserve.service.AdministrativeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * 行政管理业务层
 */
@Service
public class AdministrativeServiceImpl implements AdministrativeService {

    @Autowired
    private AdministrativeDao administrativeDao;

    public List<Administrative> findByPage(Administrative administrative) {
        return administrativeDao.findByPage(administrative);
    }

    /**
     * 物品领用新增
     * @param administrative
     * @return
     */
    @Override
    public int insertGoods(Administrative administrative) {
        //申请时，默认审核状态 审核状态（1：通过，2：未审核
        administrative.setStatus("2");
        //申请时间默认当前时间
        administrative.setAddTime(new Date());
        return administrativeDao.insertAdministrative(administrative);
    }

    @Override
    public int insertCarOrZang(Administrative administrative) {
        //申请时，默认审核状态 审核状态（1：通过，2：未审核
        administrative.setStatus("2");

        //实现 将日期串转成日期类型(格式是yyyy-MM-dd HH:mm:ss)
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        //申请时间默认当前时间
        administrative.setAddTime(new Date());
//        simpleDateFormat.parse(administrative.getStartTime())
        return administrativeDao.insertAdministrative(administrative);
    }

    @Override
    public int updateAdministrative(Administrative administrative) {
        return administrativeDao.updateAdministrative(administrative);
    }

    @Override
    public int deleteById(Integer adtrtId) {
        return administrativeDao.deleteById(adtrtId);
    }

    /**
     * 通过id获取详情
     * @param adtrtId
     * @return
     */
    @Override
    public Administrative selectAdministrativeById(Integer adtrtId) {
        return administrativeDao.selectAdministrativeById(adtrtId);
    }
}
